// pages/clearing/index.js
import { authRequest, parserDate, minutes } from '../../utils/net';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    minutes:0,
    money:0,
    lockmoney:0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var bike_id = wx.getStorageSync('bike_id')
    console.log(bike_id);
    // 结算
    authRequest({
      url: '/lock',
      method: 'POST',
      data: {
        bike_id: bike_id
      },
      success: function (res) {
        console.log(res.data.data)
        var start = parserDate(res.data.data.created_at);
        var end = parserDate(res.data.data.end_at);
        console.log(minutes(start,end));
        that.setData({
          minutes: minutes(end,start),
          lockmoney: res.data.data.money
        });
      },
      fail: function (res) {
        console.log(res);
        // fail
      }
    });
    // 获取余额
    authRequest({
      url: '/my_info',
      method: "GET",
      success: function (res) {
        that.setData({
          money: res.data.data.money.toFixed(2)
        })
      },
      fail: function (res) {
        // fail
      }
    });
  },

  cz:function () {
    // 关闭当前页面，跳转到应用内的某个页面。
    wx.reLaunch({
      url: '/pages/index/index'
    });
    wx.navigateTo({
      url: '../pay/index',
    });
  }
})